package com.jycrm.webservice.server;

import java.util.List;

import javax.xml.rpc.ServiceException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.springframework.remoting.jaxrpc.ServletEndpointSupport;

import com.jycrm.domain.user.CrmUser;
import com.jycrm.service.product.ICrmBatserverOrderService;
import com.jycrm.service.product.vo.CrmServer;
import com.jycrm.service.system.user.IUserService;

public class ServerWebServiceEndpoint extends ServletEndpointSupport implements
		IServerService {
	//private static final Log log = LogFactory.getLog(ServerWebServiceEndpoint.class);
	private static Logger log = Logger.getLogger(ServerWebServiceEndpoint.class);
	
	private ICrmBatserverOrderService crmBatserverOrderService;

	private IUserService useService;

	protected void onInit() throws ServiceException {
		super.onInit();
		useService = (IUserService) getApplicationContext().getBean(
				"userService");
		crmBatserverOrderService = (ICrmBatserverOrderService) getApplicationContext()
				.getBean("crmBatserverOrderService");
	}

	public boolean updateServiceForArray(String legendId, String userId,
			String passWd, CrmServer[] servers) {
		log.debug("say updateServiceForArray say updateServiceForArray say updateServiceForArray say updateServiceForArray");
		try {
			
			if (servers != null) {
				crmBatserverOrderService.updateService(servers,null);
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}

	public boolean updateService(String legendId, String userId, String passWd,
			List serverList) {
		
		log.debug("say updateService say updateService say updateService say updateService");
//		return false;
		try {
			if (serverList != null && !serverList.isEmpty()) {
				CrmServer[] servers = new CrmServer[serverList.size()]; 				
				serverList.toArray(servers);
				CrmUser user =null; //useService.getUserById(String.valueOf(userId));
				if (servers != null) {
					crmBatserverOrderService.updateService(servers, user);
				}
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}

}
